package com.wsh.controller.work;

import com.wsh.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;

import com.wsh.work.StudentTestService;
import com.wsh.dto.work.StudentTestDto;


/**
 * @author 王思涵
 * @date 2020-04-16
 */
@Slf4j
@Api(tags = "学生测试管理")
@RestController
@RequestMapping("/work/studentTest")
public class StudentTestController {

    @Autowired
    private StudentTestService studentTestService;

    @GetMapping("/list")
    @PreAuthorize("@el.check('studentTest:list')")
    @ApiOperation(value = "学生测试列表")
    public Object list(StudentTestDto studentTestDto) {
        log.info("StudentTestControlle ==> list params={}", studentTestDto);
        return JsonResult.success(studentTestService.getList(studentTestDto));
    }

    @GetMapping("/getById")
    @PreAuthorize("@el.check('studentTest:getById')")
    @ApiOperation(value = "查询学生测试")
    public Object getById(@RequestParam String formId) {
        return JsonResult.success(studentTestService.queryVo(formId));
    }

    @PostMapping("/save")
    @PreAuthorize("@el.check('studentTest:save')")
    @ApiOperation(value = "保存学生测试")
    public Object save(@Valid @RequestBody StudentTestDto studentTestDto) {
        return JsonResult.success(studentTestService.saveStudentTest(studentTestDto));
    }

    @DeleteMapping("/del")
    @PreAuthorize("@el.check('studentTest:del')")
    @ApiOperation(value = "删除学生测试")
    public Object del(@RequestParam String formId) {
        return JsonResult.success(studentTestService.removeById(formId));
    }

}
